<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class RegisterRequest extends FormRequest
{
    /**
     * Determine if the blacklist is authorized to make this request.
     *
     * @return bool
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules(): array
    {
        return [
            'name' => [
                'required',
                'string',
                'regex:/^[A-Za-z0-9]+$/',
                'min:3',
                'max:15'
            ],
            'password' => [
                'required',
                'regex:/^[A-Za-z0-9]+$/',
                'min:6',
                'confirmed'
            ]
        ];
    }

    public function messages(): array
    {
        return [
            'name.required' => '请输入用户名',
            'name.string' => '用户名格式不正确',
            'name.regex' => '用户名只能是英文或数字组合',
            'name.min' => '用户名不能小于3个字符',
            'name.max' => '用户名不能大于15个字符',
            'password.required' => '请输入密码',
            'password.regex' => '密码只能是英文或数字组合',
            'password.min' => '密码最小6位',
            'password.confirmed' => '两次输入的密码不一致'
        ];
    }
}
